<?php

namespace app\controller;

use app\BaseController;

use app\service\accountService;

class Index extends BaseController
{
    public function index()
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">14载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
    }

    public function Hello($name = 'ThinkPHP6') :string
    {
        return 'hello,' . $name;
    }

    public function db(): string
    {

//       查询所有 结果转换为数组
//       $select = Account::select() ->toArray();
        // 查询某一列 指定 id字段值为 索引   * 返回所有的值
        // $result = Account::where('id',1) -> column('userName','id');


        // 模型操作，调用toArray()
        // 返回格式的处理json_encode()
        //  return

        // 分批处理
//        $result = Account:: chunk(3, function ($user) {
//            $res = json_encode($user);
//
//            echo json_encode(['code' => 200 , 'msg' => 'message' , 'data' => $user] , JSON_UNESCAPED_UNICODE);
//        },'id') ;

//        $list = ['userName' => '阿森哦', 'password' => '1233456'];
//        $result =  Account:: save($list);

        // 更新数据
//        $result = Account::where('id',1) -> update(['userName' => '我是更新的名字']);

        // 删除数据

//        $result = Account::find(4)
//            ->where('name','=','asen');
//
//        if (true) {
//            $result->where();
//        }
//
//        $result->select();
//        print_r(json_encode($result));


        // 获取用户数据

//        $userName = request()->param('userName');
//
//        $data = [];
//
//        $data['name'] = $userName;
//
//
//        return json($data)->code(200);

//        $result1 = Account::select() -> toArray();
//        print_r($result1);


//        print_r( $result);


//        return $select;
//        print_r($data);


        return 'db123';

    }

    public function resigin()
    {

//        $userData = new User();
//        $userData->userName = $_POST['userName'];
//        $userData->password = $_POST['password'];
        $data = [
            'userName' => $_POST['userName'],
            'password' => $_POST['password'],
        ];
        $result = accountService::resign($data);

        if ($result) {
            return json(['msg' => '注册成功','code' => 200], 200);
        }
    }
}
